//
//  HNSH_MyTeamAlert.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/5/30.
//

#import "HNSH_MyTeamAlert.h"

#import "HNSH_PopupController.h"

@interface HNSH_MyTeamAlert ()

/* nyPopView */
@property(nonatomic, strong) HNSH_PopupController *hhzxPopView;
/* cancelButton */
@property (nonatomic, strong) UIButton *closeButton;
/* 实名 */
@property (nonatomic, strong) UILabel *smLabel;
/* 未实名 */
@property (nonatomic, strong) UILabel *wsmLabel;

/* model */
@property (nonatomic, strong) HNSH_MyTeamModel *model;

@end

@implementation HNSH_MyTeamAlert

- (instancetype)initWithFrame:(CGRect)frame model:(HNSH_MyTeamModel *)model {
    self = [super initWithFrame:frame];
    _model = model;
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        [self configUI];
    }
    return self;
}

- (void)configUI {
    UIImageView *imgV = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"team_icon_alert"]];
    imgV.frame = CGRectMake(16, 16, 20, 20);
    [self addSubview:imgV];
    
    UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(44, 16, 200, 20)];
    titleLabel.text = @"团队数据";
    titleLabel.textColor = [UIColor appBlackLabelColor];
    titleLabel.font = [UIFont boldSystemFontOfSize:14];
    [self addSubview:titleLabel];
    
    [self addSubview:self.closeButton];
    self.closeButton.frame = CGRectMake(self.width-48, 0, 48, 48);
    
    UILabel *smLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 64, self.width/2, 28)];
    smLabel.text = self.model.info.team_certify_count;
    smLabel.textColor = [UIColor appBlackLabelColor];
    smLabel.font = [UIFont boldSystemFontOfSize:20];
    smLabel.textAlignment = NSTextAlignmentCenter;
    [self addSubview:smLabel];
    self.smLabel = smLabel;
    UILabel *smTitleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 96, self.width/2, 17)];
    smTitleLabel.text = @"团队实名人数";
    smTitleLabel.textColor = [UIColor appGrayLabelColor];
    smTitleLabel.font = [UIFont systemFontOfSize:12];
    smTitleLabel.textAlignment = NSTextAlignmentCenter;
    [self addSubview:smTitleLabel];
    
    UILabel *wsmLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.width/2, 64, self.width/2, 28)];
    wsmLabel.text = [NSString stringWithFormat:@"%ld",self.model.info.team_count - [self.model.info.team_certify_count integerValue]];
    wsmLabel.textColor = [UIColor appBlackLabelColor];
    wsmLabel.font = [UIFont boldSystemFontOfSize:20];
    wsmLabel.textAlignment = NSTextAlignmentCenter;
    [self addSubview:wsmLabel];
    self.smLabel = smLabel;
    UILabel *wsmTitleLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.width/2, 96, self.width/2, 17)];
    wsmTitleLabel.text = @"团队未实名人数";
    wsmTitleLabel.textColor = [UIColor appGrayLabelColor];
    wsmTitleLabel.font = [UIFont systemFontOfSize:12];
    wsmTitleLabel.textAlignment = NSTextAlignmentCenter;
    [self addSubview:wsmTitleLabel];
}

- (void)showView {
    self.hhzxPopView = [[HNSH_PopupController alloc]init];
    self.hhzxPopView.dismissOnMaskTouched = NO;
    self.hhzxPopView.layoutType = PopupLayoutTypeCenter;
    self.hhzxPopView.slideStyle = PopupSlideStyleFade;
    [self.hhzxPopView presentContentView:self duration:0.25 springAnimated:YES inView:kSTWindow];
    self.hhzxPopView.popupView.layer.cornerRadius = 10.0f;
    self.hhzxPopView.popupView.layer.masksToBounds = YES;
}

- (void)closeView {
    [self.hhzxPopView dismissWithDuration:0.25 springAnimated:YES];
}

- (UIButton *)closeButton {
    if (!_closeButton) {
        _closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_closeButton setImage:[UIImage imageNamed:@"base_icon_close"] forState:UIControlStateNormal];
        __weak __typeof(&*self)weakSelf = self;
        [[_closeButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
            [weakSelf closeView];
        }];
    }
    return _closeButton;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
